import { API } from '@/services/model/baseModel';
import { AddressModel } from '@/services/model/addressModel';
import config from '@/utils/config';
import { request } from '@/utils/http';

/**
 * 获取地址列表
 * @returns res
 */
const getAddressList = () => {
  return request.get<API<AddressModel[]>>(config.url.address_list);
};

/**
 * 获取地址信息
 * @returns res
 */
const getAddressInfo = (id: number) => {
  return request.post<API<AddressModel>>(config.url.address_info, { id: id });
};

/**
 * 新增地址
 * @param params 地址
 * @returns res
 */
const addAddress = (params: AddressModel) => {
  return request.post<API<String>>(config.url.address_add, params);
};

/**
 * 编辑地址
 * @param params 地址
 * @returns res
 */
const editAddress = (params: AddressModel) => {
  return request.post<API<String>>(config.url.address_edit, params);
};

/**
 * 删除地址
 * @param id 地址ID
 * @returns res
 */
const deleteAddress = (id: number) => {
  return request.post<API<String>>(config.url.address_delete, { id: id });
};

export { getAddressList, getAddressInfo, addAddress, editAddress, deleteAddress };
